/**
 * Created by Administrator on 2016/6/19 0019.
 */



define([], function () {

    function _controller($scope, $routeParams, $location, $timeout, httpService) {


        var model ="Property";
        $scope.data = [];
        $scope.editProperty = {};

        $scope.editObject = function(arg_type, arg_o){
            $scope.editProperty = {};
            $scope.editProperty.type = arg_type;
            $scope.editType = arg_type == 0 ? "属性":"属性组";
            if(arg_o) $scope.editProperty = arg_o;
        };


        $scope.save = function () {
            $scope.$broadcast('show-errors-check-validity');
            if (!$scope.userForm.$valid) return;
            console.log($scope.editProperty);
            if(!$scope.editProperty.pid) $scope.editProperty.pid = '0';
            httpService.save(model, $scope.editProperty).then(function (data) {
                $scope.msg.show(data);
                $scope.getAll();
            });
        };


        $scope.getAll = function () {
            httpService.get(model, {all:true, sort:"createdAt"}).then(function (data) {
                $scope.models = data.data.data;
            });

        };

        $scope.delete = function(m){
            httpService.del(model, m.objectId).then(function (data) {
                httpService.removeParent(model, m.objectId).then(function (data) {
                    $scope.msg.show(data);
                    if($scope.isHandleSuccess(data)){
                        $scope.getAll();
                    }
                });
            });
        };

        $scope.getAll();

    }

    return _controller;
});

